import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

public class JobMain {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration, "PayrollMapper");
        job.setJarByClass(JobMain.class);

        job.setInputFormatClass(TextInputFormat.class);
      TextInputFormat.addInputPath(job, new Path("file:///D:\\input"));
        // TextInputFormat.addInputPath(job, new Path("hdfs://node1:8020/payroll"));

        job.setMapperClass(PayrollMapper.class);
        job.setOutputKeyClass(PayrollSortBean.class);
        job.setMapOutputValueClass(Text.class);

        job.setPartitionerClass(PayrollPartitioner.class);
        job.setNumReduceTasks(3);

       job.setReducerClass(PayrollReduceer.class);
       job.setOutputKeyClass(PayrollSortBean.class);
       job.setOutputValueClass(NullWritable.class);

        job.setOutputValueClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job, new Path("file:///D:\\output1105"));
        // TextOutputFormat.setOutputPath(job, new Path("hdfs://node1:8020/payroll_output"));
        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);

    }


}

